package com.yugao.fintech.antelope.infra.weixin.mp.controller;

import com.yugao.fintech.antelope.infra.weixin.mp.model.entity.MpMenu;
import com.yugao.fintech.antelope.infra.weixin.mp.model.rqrs.MpMenuReq;
import com.yugao.fintech.antelope.infra.weixin.mp.service.MpMenuService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 公众号菜单
 * 

 */
@Api(tags = "公众号菜单")
@RestController
@RequestMapping("/mpMenu")
public class MpMenuController {
    @Autowired
    private MpMenuService mpMenuService;

    @ApiOperation(value = "保存并发布菜单")
    @RamResource(action = "weixin:mpMenu:releaseMenu", name = "保存并发布菜单", type = ActionType.WRITE)
    @PostMapping("/releaseMenu")
    public Resp<?> releaseMenu(@RequestBody @Validated MpMenuReq req) {
        mpMenuService.releaseMenu(req);
        return Resp.ok();
    }

    @ApiOperation(value = "获取微信公众号菜单")
    @RamResource(action = "weixin:mpMenu:listMenu", name = "获取微信公众号菜单", type = ActionType.READ)
    @GetMapping("/listMenu")
    public Resp<List<MpMenu>> listMenu() {
        List<MpMenu> list = mpMenuService.listMenu();
        return Resp.ok(list);
    }

    @ApiOperation(value = "删除公众号菜单")
    @RamResource(action = "weixin:mpMenu:deleteMenu", name = "删除微信公众号菜单", type = ActionType.WRITE)
    @DeleteMapping("/deleteMenu")
    public Resp<?> deleteMenu() {
        mpMenuService.deleteMenu();
        return Resp.ok();
    }
}
